package cn.wwcyc.service;

import cn.wwcyc.domain.TjYjSs;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.util.concurrent.*;

//@Service
//@EnableScheduling
//未使用，暂未使用，报警功能在YjBjXxImpl类里
public class BjService {
    private ScheduledExecutorService scheduler;//定时任务调度器，用于执行含水仪任务
    Runnable timerTask;
    private ScheduledFuture<?> scheduledFuture;
    private ThreadPoolExecutor executor;//线程池，用于执行含水仪任务
    private  final int CORE_POOL_SIZE = 300; // 核心线程数
    private  final int MAXIMUM_POOL_SIZE = 10000; // 最大线程数
    private  final long KEEP_ALIVE_TIME = 120L; // 线程空闲后的存活时间: 120秒
    private final int INIT_PERIOD = 60; //含水率采集频率，60秒一次
    private final int QueueSize = 20;
    public void test() {
        timerTask = new Runnable() {
            @Override
            public void run() {
                System.out.println("定时任务执行中...");
                Future<TjYjSs> future = executor.submit(new Callable<TjYjSs>() {
                    @Override
                    public TjYjSs call() throws Exception {
                        return null;
                    }
                });
                try {
                    TjYjSs tjYjSs = future.get();
                    System.out.println(tjYjSs);
                } catch (InterruptedException | ExecutionException e) {
                    e.printStackTrace();
                }
            }
        };
        BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<>(QueueSize);
        executor = new ThreadPoolExecutor(
                CORE_POOL_SIZE,
                MAXIMUM_POOL_SIZE,
                KEEP_ALIVE_TIME, TimeUnit.SECONDS,
                workQueue,
                new ThreadPoolExecutor.CallerRunsPolicy());
        scheduler = Executors.newScheduledThreadPool(1);

        scheduledFuture = scheduler.scheduleAtFixedRate(timerTask, 0, 10, TimeUnit.SECONDS);
    }

    public static void main(String[] args) {
//        new BjService().test();
        Long a = 1L;
        System.out.println(a.equals(1L));
    }
}
